package com.wpen.unit.exception;

import com.wpen.unit.utils.MessageUtils;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

/**
 * 业务异常处理类
 * 
 * @author Admin
 *
 */
@Slf4j
@Getter
public class BizException extends RuntimeException {
    private static final long serialVersionUID = 8747773293464966547L;

    private String errCode;
    private Object[] errArgs;

    public BizException(String errCode) {
        super();
        this.errCode = errCode;
    }

    public BizException(String errCode, Object... message) {
        super();
        this.errCode = errCode;
        this.errArgs = message;
    }

    public BizException(Throwable cause) {
        super(cause);
    }

    public BizException(String message, Throwable cause) {
        super(message, cause);
    }

    @Override
    public String toString() {
        try {
            return MessageUtils.message(errCode, errArgs);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return errCode + "???";
        }
    }

    @Override
    public String getMessage() {
        return toString();
    }
}
